<?php
namespace app\admin\model;

use think\Db;
use think\Model;

class BusPreOrderPhone extends Model {
	public function searchPhoneAttr($query, $value, $data) {
		if ($value) {
			$query->where('ope.phone', $value);
		}

	}
	public function searchStatusAttr($query, $value, $data) {
		if ($value || $value == "0") {
			$query->where('ope.status', $value);
		}

	}

	public function getStatusAttr($value) {
		$status = [0 => '未发送', 1 => '发送中', 2 => '成功', 3 => '失败'];
		return $status[$value];
	}

	public function getSmTypeAttr($value) {
		$status = [1 => '验证码', 2 => '营销'];
		return $status[$value] ?? '';
	}

	public function getCreateTimeAttr($value) {
		if ($value) {
			return 'GMT+8 ' . $value;
		}
	}

	public function getCallbackTimeAttr($value) {
		if ($value) {
			return 'GMT+8 ' . $value;
		}
	}

	public function getSendTimeAttr($value) {
		if ($value) {
			return 'GMT+8 ' . $value;
		}
	}
	/**
	 * 查询订单下的号码
	 * @创建     lf
	 * @修改
	 * @修改时间   2025-08-21T14:12:47+0800
	 * @描述
	 * @param  [type]                   $request [description]
	 * @return [type]                            [description]
	 */
	public function getOrderPhoneAll($request) {
		$data = $this->alias('ope')->withSearch(['phone', 'status'], $request)
			->field('ope.*')
			->join('bus_pre_order order', 'order.id=ope.bus_pre_order_id', 'left')
			->join('bus_actual_order actual', 'ope.id=actual.bus_pre_order_phone_id', 'left')
			->join('bus_channel c', 'c.channel_id=order.channel_id', 'left')
			->where("c.p_id='" . session('relate_id') . "' or c.channel_id='" . session('relate_id') . "'")
			->where('bus_pre_order_id', $request['id'])
			->limit(($request['page'] - 1) * $request['limit'])
			->select();
		$total = 100;
		// $total = $this->alias('order')->withSearch(['name', 'create_time'], $request)
		// ->count();

		return ['count' => $total, 'data' => $data];

	}

}